﻿public class CommandHelper
{
    static string GetValue(string key, string defaultValue)
    {
        string[] commandlines = System.Environment.GetCommandLineArgs();

        string ret = defaultValue;
        foreach (string command in commandlines)
        {
            string[] temp = command.Split(":"[0]);
            if (string.Equals(temp[0], key))
            {
                ret = temp[1];
                break;
            }
        }
        return ret;
    }

    static int GetValue(string key, int defaultValue)
    {
        return int.Parse(GetValue(key, defaultValue.ToString()));
    }

    static bool GetValue(string key, bool defaultValue)
    {
        return (GetValue(key, defaultValue ? "1" : "0") == "1");
    }

    // 导出类型
    public static EditorConfig.ExportType ExportType { get { return (EditorConfig.ExportType)(GetValue("et", (int)EditorConfig.ExportType.PROJECT)); } }

    // 项目名称
    public static string ProductName { get { return GetValue("product_name", "dk_ios"); } }
    // 用户宏
    public static string DefineSymbols { get { return GetValue("symbols", ""); } }
    // 图标
    public static string IconName { get { return GetValue("icon", ""); } }
    // IL2CPP
    public static int Arch { get { return int.Parse(GetValue("arch", "3")); } }
    // 开发者模式
    public static bool IsDevelopment { get { return (GetValue("development", false)); } }
    // 输出路径
    public static string OutputPath { get { return GetValue("output", "output"); } }

    public static void InitPropertyFromCommandline()
    {
        ConfigHelper.ProjectName = GetValue("project_name", ConfigHelper.ProjectName);
        ConfigHelper.Version = GetValue("version", ConfigHelper.Version);
        ConfigHelper.BundleId = GetValue("id", ConfigHelper.BundleId);

        ConfigHelper.Release = (ReleaseType)GetValue("release", (int)ConfigHelper.Release);

        ConfigHelper.CheckUpdate = GetValue("update", ConfigHelper.CheckUpdate);
        ConfigHelper.ResourceSplit = GetValue("split", ConfigHelper.ResourceSplit);
        ConfigHelper.UseLuaJit = GetValue("luajit", ConfigHelper.UseLuaJit);
    }
}